package demo.java.lang.management.jvm;

import java.lang.management.ManagementFactory;
import java.math.BigDecimal;

/**
 * @author mandy.hu
 *
 */

public class JVMUtils {

    private static String pid;

    public final static String getPID() {
        if (pid == null) {
            String name = ManagementFactory.getRuntimeMXBean().getName();

            String[] items = name.split("@");

            pid = items[0];
        }

        return pid;
    }

    public static double formatDouble(Double tmp) {
        if (tmp == null)
            return 0d;
        BigDecimal b = new BigDecimal(tmp);
        return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }
}
